import uuid

import jsonpath
import requests


class BaseApi:
    BaseUrl = 'https://qyapi.weixin.qq.com/cgi-bin'

    def send(self, method, url, **kwargs):
        url = self.BaseUrl + url
        return requests.request(method=method, url=url, **kwargs)

    def get_access_tooken(self, corpid, corpsecret):
        '''
        获取access_tooken
        :return:
        '''
        corpid = corpid
        corpsecret = corpsecret
        url = '/gettoken'
        params = {
            "corpid": corpid,
            "corpsecret": corpsecret
        }

        r = self.send("GET", url, params=params)
        return r.json()['access_token']

    def wework_jsonpath(self, json_obj, expr):
        return jsonpath.jsonpath(json_obj, expr)

    def get_union_id(self):
        return str(uuid.uuid4()).split("-")[0]
